package Thread;

class MyThread extends Thread {
    public MyThread(String name) {
        super(name);
    }

    @Override
   public void run() {
       while (true){
           try {
               Thread.sleep(1000);
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
           System.out.println("hello t");
       }
    }
}
public class ThreadDemo1 {
    //第一种写法是使用Thread的run描述线程入口
    public static void main(String[] args) {
        Thread t = new MyThread("猪猪侠");//向上转型
        t.start();//会创建新的线程
        //t.run();//不会创建新的线程
        while (true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("hello main");
        }
    }
}
